﻿using System;
using System.Net.Mime;
using System.Text;
using System.Web;
using System.Web.Mvc;
using MiniWeb.Core.Dtos;
using MiniWeb.Core.Entities;
using MiniWeb.Core.Enums;
using MiniWeb.Task;
using System.Linq;
using MiniWeb.Web.Controllers.Code;
using MiniWeb.Web.Controllers.Web.web.ViewModels;
using WFramework;
using WFramework.Common;
using WFramework.MvcPager;
using WFramework.Utility;

namespace MiniWeb.Web.Controllers.Web.NewsCenter
{
    public class NewsCenterController:BaseController
    {
        private readonly NewsTask _newsTask = new NewsTask();
        private readonly NewsTypeTask _newsTypeTask = new NewsTypeTask();

        //商城咨询公告列表
        public ActionResult List(int? tid,int pageindex = 1, int pagesize = 16)
        {

            ViewData["typelist"] = _newsTypeTask.GetAll(10, "ParentType = 1", "sort");
            var pagedList = _newsTask.GetPagedList(1, tid, null, null, pageindex, pagesize);
            var model = new PagedList<NewsDto>(pagedList.ToList(), pageindex, pagesize, pagedList.TotalItemCount);
            return View(model);
        }

        //商城咨询公告详细页
        public ActionResult Show(int id)
        {
            var model = _newsTask.GetById(id);
            if (model == null)
            {
                return RedirectToAction("Index", "Home");
            }
            ViewData["typelist"] = _newsTypeTask.GetAll(10, "ParentType = 1", "sort");
           
            return View(model);
        }

    }
}
